<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog"
             :title="isAdd ? '新增' : '编辑'"
             append-to-body width="600px">
    <el-form ref="form" :model="form" :rules="rules"  label-width="85px">
      <el-form-item label="题库名称" prop="bankName">
        <el-input v-model="form.bankName" maxlength="20"/>
      </el-form-item>
      <el-form-item label="题库配置" prop="queStatus">
        <el-select v-model="form.queStatus" clearable style="width: 475px" placeholder="题库状态">
          <el-option v-for="item in dictMap.bank_options" :key="item.value" :label="item.label"
                     :value="item.value-0">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="题库描述">
        <el-input
          type="textarea"
          :autosize="{ minRows: 7, maxRows: 11}"
          placeholder="请输入题库描述"
          v-model="form.bankDesc">
        </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import initDict from '@/mixins/initDict'
  import { add } from '@/api/business/questionBank'
  export default {
    mixins: [initDict],
    name: 'from',
    props: {
      isAdd: {
        type: Boolean,
        required: true
      }
    },
    data() {
      return {
        loading: false,
        dialog: false,
        specialty: [],
        jobs:[],
        form: {
          bankName: '',
          bankDesc: '',
          //specialtyId: null,
          //jobId: null,
          source: '',
          type:1
        },
        rules: {
          bankName: [
            { required: true, message: '请输题库名称', trigger: 'blur' }
          ],
          queStatus: [
            { required: true, message: '请选择题库状态', trigger: 'change' }
          ]
        }
      }
    },
    created() {
      this.$nextTick(() => {
        this.getDictMap('bank_options')
      })
    },
    methods: {
      cancel() {
        this.dialog = false
        this.form={
          bankName: '',
          bankDesc: '',
          source: '',
          type:1
        }
      },
      doSubmit() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.doAdd()
          }
        })
      },
      doAdd() {
        add(this.form).then(res => {
          this.$notify({
            title: '操作成功',
            type: 'success',
            duration: 2500
          })
          this.loading = false
          this.$parent.init()
          this.cancel()
        }).catch(err => {
          this.loading = false
          console.log(err)
        })
      },
    }
  }
</script>
